/**
 * 计时-计算帧率
 * @date   2011-3-20
 * @author tianye
 */
package cn.edu.dlut.WingGame.Tools;

import android.util.Log;
import cn.edu.dlut.WingGame.BaseType.WingColor;
import cn.edu.dlut.WingGame.Graphic.GLFont;

public class FPSCounter {
	public float fps;
	private int count;
	private long lasttime;
	private GLFont font = new GLFont();

	public FPSCounter() {
		font.creatFont(12, new WingColor(255, 0, 0, 255));
		count = 0;
		lasttime = System.currentTimeMillis();
	}

	public void nextFrame() {
		count++;
		if (count >= 60) {
			fps = 1000f * count
					/ (System.currentTimeMillis() - lasttime);
			lasttime = System.currentTimeMillis();
			count = 0;
			Log.v("FPS", "" + fps);
		}

	}

	public void drawFPS() {
		font.drawText(0, 0, "FPS:" + fps);
	}
}